开发者

issue dynamically checking password

Here is my scenario, I present the user with a table of tests, which I have retrieved from my database in a loop and created a form for each test(row of table). So each has a submit button to execute that particular test.

basics of my loop:

while ($ts = mysql_fetch_assoc($test_info))
{
 //PRESENT VALUES $ts['name'] in table within a unique form etc.
}

What I am trying to do and failing is, on clicking a particular submit button for a test, to run a JS function which checks; if the test has a password attached, if it does, present a popup form for password input, and on submitting that small form check if password is correct, if it is submit the original test form.

My problem is that I cannot parse the password value attached to that form to my javascript.

so ideally i want to do this:

<input id='submit' type='button' onclick='JSfunction(test_password)' value='execute test' >

So I can somehow parse a value from that particular form to a javascr开发者_开发知识库ipt function without actually submitting the form.

and I believe I know how to do the rest in my JSfunction.

I hope somebody can follow my poor explanation and point me in the right direction.

Many thanks,


When a form should have a password associated with it, add the following:

<input type="hidden" name="has_password" value="yes" />
<input type="hidden" name="password" value="" />

Then, in your check triggered by the submit button (assuming the button itself is the this context):

if ($(this).parent().find(':input:hidden[name=has_password]').val() == 'yes') {
    // pop password request
    return false;
}

You'll need a way to store the context of the current form, and I can suggest a few if you like, but you can then populate the password into the hidden field for it and submit as normal. By the way, you might want to consider onSubmit instead of the submit button's onClick, as onSubmit will catch attempts by scripts to perform a submit. If you do this, just remove the .parent() portion of the above, as the <form> element should be the this context.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜