Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

send variable with this.form.submit, or something like it...

Status
Not open for further replies.

rbauerle

Programmer
Oct 16, 2001
48
BR
Hi all!

I'm working on a form which the user reloads many times while filling it to change fields accaording to what the user fills.
My problem is that i need the focus to be on the last filled field when the page is reloaded.
I'm using this.form.submit(page.php).
I thougth of sending a variable to identify the field to focus, so i tried this.form.submit(page.php?submit=myField). It didn't work out. The variable was not sent or I couldn't get it latter.I tried reaching it with both, get and post.
Well, any suggestion are welcome.
Thanks a lot.
 

Why not have a hidden form field that holds the name of the last field to have gained focus?

Hope this helps,
Dan
 
I don't understand. But, I thought I understood this bit.

"My problem is that i need the focus to be on the last filled field when the page is reloaded."

You could save the field to document.cookie and then focus with..

Code:
window.onload=document.getElementById(document.cookie).focus();

At least I think that's right. Hope this is more help that trouble :)

----------
I'm willing to trade custom scripts for... [see profile]
 
I can´t have a hidden field, because I have several fields that submit the form. I have to send the name of the field to be focused only when this field is the one that submits the form...
 

>> I can´t have a hidden field, because I have several fields that submit the form. I have to send the name of the field to be focused only when this field is the one that submits the form...

I'm not quite sure I understand what you mean by "this field" - which field? ;o)

I also don't understand why you cannot have a hidden field... Surely you can populate it before the form submission, regardless of which field (?!) submitted the form?

Dan
 
I mean I can't have an <input type="hidden" ...>.
I need something that will be posted only when I click an specific button, or field.
 
rbauerle,

You can use JavaScript to dynamically set the value of a hidden form field. Here's two ways to do what I think you're asking:

Using cookies:
Code:
<body onload="try{document.getElementById(document.cookie).focus()}catch(ex){};">
<form>
<input type="submit" name="submit1" onfocus="document.cookie=this.name">

<input type="submit" name="submit2" onfocus="document.cookie=this.name">

<input type="text" name="text1" onfocus="document.cookie=this.name">

Using a hidden field: (Assumes you're going to reload the page with the field name in the url like myPage.html?submit1)
Code:
<body onload="try{document.getElementById(document.location.search(1)).focus()}catch(ex){};">
<form>
<input type="hidden" name="lastFieldTouched">

<input type="submit" name="submit1" onfocus="this.form.lastFieldTouched.value=this.name">

<input type="submit" name="submit2" onfocus="this.form.lastFieldTouched.value=this.name">

<input type="text" name="text1" onfocus="this.form.lastFieldTouched.value=this.name">

Is this close to what you are looking for?

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 

>> I mean I can't have an <input type="hidden" ...>. I need something that will be posted only when I click an specific button, or field.

Then use JS to only set the value of the hidden field when you're sumbitting via one of your "allowed" routes. Surely it doesn't matter if you get a blank hidden field (with known name) getting submitted? You can just ignore it server-side, right?

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top