1

BEFORE CHAOS

I used to have this one...

at the head part

<script type="text/javascript">$(function() { $("form.openid:eq(0)").openid(); });</script>

in the jquery.openid.js

var direct = function () {
    var $li = $(this);

    $this.unbind('submit').submit(function() {
      $id.val($this.find("li.highlight span").text());
    });
    $this.submit();
    return false;
  };

and in the body part

<form class="openid" method="post" action="/Login.xhtml?ReturnUrl="> 
  <div>
   <ul class="providers">  
    <li class="direct" title="Google"> <img src="images/googleW.png" alt="icon" />
   </ul>
  </div>  
</form>

which works like a charm.

AFTER CHAOS

Now since i would like to add the all above as content in an ASP.NET page i made the appropriate changes

at the head part in The MasterPage

<script type="text/javascript">$(function () { $("#test.openidd").openid(); });</script>

in the body part, i added the div with id=test and class equal to openidd.

<div id ="test" class="openidd">
  <ul class="providers">
  <li class="direct" title="Google"> <img src="images/google.png" />     
  </ul>
</div> 

So what changes should i make to the jquery.openid.js to make it work?

I mean in the first case the $this refers to form.openid:eq(0) In the second case the $this refers to #text.openidd and the form is never submitted.

I guess something like this one $this.FindParentForm exists in JQUERY, but i have no clue!

Please keep your answers as simple as possible, since i am a newbie

Thank you in advance.

UPDATE From the answers i have seen so far, i guess or i have not set my question clear or i am soooo newbie. I added the div tag as enclosure for the elements. The form contains other <li>'s etc that jquery messes with. And i would not like that! That's why in my post i believe that the work has to be done in the jquery.openid.js file... something like

$this.GETParentFORM.unbind('submit').submit(function() {
   $id.val($this.GETParentFORM.find("li.highlight span").text());
   });
$this.GETParentFORM.submit();
3
  • 1
    I do not understand what function you call here $("form.openid:eq(0)").openid(), and where you call the function var 'direct = function () {...' Commented Mar 30, 2011 at 7:11
  • Why are you desperately try to use this ? instead of using eq() or such things, you may try to pass a variable when you call openid(), maybe unique id of the related form like .openid(<formid>) and use that id within openid function instead of $this Commented Mar 31, 2011 at 15:22
  • This will get you the parent form: carnotaurus.tumblr.com/post/3121098288/… Commented Apr 3, 2011 at 11:43

6 Answers 6

1

One thing to look out for in ASP.NET with jQuery is that any control that has runat="server" will have an auto-generated ID based on the original ID. Just saying, especially if you're planning to select via IDs on your jQuery.

Having said that, supposedly, there's only one form in any ASP.NET page (the one located on your MasterPage). So to select that, all you actually have to do is go

$('form')

but if you want to go your route, I'd use

$('#test.openidd').closest('form')
Sign up to request clarification or add additional context in comments.

1 Comment

Like I said, ASP.NET pages should only have one form... so doesn't $('form').openid(); work for you?
0

CODE

$(this).parents('form#myId')...

EXAMPLE

http://jsfiddle.net/ngdcs/

Comments

0

You could probably change it to:

<script type="text/javascript">$(function () { $("#test.openidd").parents('form').openid(); });</script>

Although I think it would be better to give your form an id like:

<form id="submitForm5" ...>

and then change the javascript code to:

<script type="text/javascript">$(function () { $("#submitForm5").openid(); });</script>

1 Comment

I don't think this'll work, because the ID you give your form won't be the same ID when it reaches the browser (due to ASP.NET's nuances). You might want to try $('[id$="submitForm5"]') instead.
0

Maybe try this?

$("#test.openidd").parent().openid();

Comments

0
$('form').find('li.highlight span').text();

IE

$('form').unbind('submit').submit(function() {
   $id.val($('form').find("li.highlight span").text());
   });
$('form').submit();

Comments

0

Since ASP.NET modify the form's id, you can still get the form element by using closest. In this code, you get the test.openidd's closest elemet called form which would be the form itself.

$('#test.openidd').closest('form').unbind('submit').submit(function() {
   $id.val($('#test.openidd').closest('form').find("li.highlight span").text());
   });
$('#test.openidd').closest('form').submit();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.