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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display form action as variable?

Status
Not open for further replies.

XaceX

Programmer
Jul 31, 2007
3
US
Is there a way to send the form action to a variable instead of hitting submit?

basically

i want to see what and how the form is being sumitted before actually submitting it. like i know whent it is Method get it takes action?name=value&name2=value2 i need it to display what should have been sent or if its method post i need to see what that will be

any help would be greatly appreciated
 
You can use onsubmit to do this kind of thing before the form is submitted (and it can be used to prevent submission).
Code:
<form method="get" [b]onsubmit="checkFormData()"[/b]>...</form>
You would then have to code the javascript function checkFormData() (of course) to iterate over all the form elements and alert/log the contents.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
I have seen options like that but its not what i need.. basically i am not going to know what all is in the form.

i am using the resulting url to launch threw a function.

so i need something that would store what the url being opened is instead of opening the form in the page. if that makes any sense.

I.E. <a href= target='_blank>launch me </a>

but instead of target =_blank something like target= var a

then

<script>
function whatever (){
window.open=a;
}
</script>


and launch that url from that variable


is somethign like this possible?
 
You can fake a form being submitted if it uses the GET method by appending parameters to the end of the URL - and you would be best to do it something like this:
Code:
<a href="[URL unfurl="true"]http://www.google.co.uk"[/URL] onclick="doLink(this.src, 'formId');return false;">Google</a>
This assumes that 'formId' is the id of a form that you have filled out. You would need to write the function doLink() to add in the parameters and redirect the browser (see below).

Here is an example of how you might do this:
Code:
<form action="mypage.php" id="editForm">
<input name="firstname" value=""/>
<input name="lastname" value=""/>
<input name="email" value=""/>
<input name="country" value=""/>
</form>
...
<a href="mypage.php" onclick="doLink(this.src, 'editForm');return false;">Send details</a>
...
<script type="text/javascript">
function doLink(l_sURL, l_sFormId) {
  var l_sParams = "?";
  var l_oForm = document.forms[l_sFormId];
  var l_pInputs = l_oForm.getElementsByTagName('INPUT');
  for (var loop=0, max=l_pInputs.length; loop<max; loop++) {
    l_sParams += l_pInputs[loop].name + '=';
    l_sParams += l_pInputs[loop].value + '&';
  }
  document.location = l_sURL + l_sParams;
}
</script>
Something like that anyway.

You'll have to manage radios, checkboxes and selects a little differently (an exercise for the reader so to speak). Also it's a little sloppy to leave an & character at the end - but not going to be a real problem.

Let us know how you go.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top