Solved

Problem with html form processing

Posted on 2011-09-29
10
329 Views
Last Modified: 2012-08-13
I am trying to process a form without using "submit" button so I can do validation before submit, however the form seems to be submitted without me calling the submit function  after validation. It waits for validation to complete and then fires a submit. a few seconds later, depending on the browser. Here is the code I have extracted, I have double checked for any JQuery events and it seems not. I have extracted what I think is the relevant code but I can provide more.

<form name="cwccars" id='cwccars' action="php/createrecord.php" method="post">
<div id="labels">
<label for="registration">Registration</label>
<label for="carmake">Make</label>
<label for="carmodel">Model</label>
<label for="year">Year</label>
<label for="cost">Cost</label>
<label for="expenses">Expenses</label>
<label for="sell">Sold</label>
<label for="selldate">Date Sold</label>
<label for="seller">Salesman</label>

</div>
<div id="entries">
<input name="registration" id='registration' type="text" placeholder=" Registration Number" />
<input name="carmake" id='carmake' type="text" placeholder="/Pick Make of Car" />
<input name="carmodel" id='carmodel' type="text" placeholder="/Pick Model" />
<input name="year" id='year' type="text" placeholder=" Year of Manufacture" />
<input name="cost" id='cost' type="text" placeholder=" Cost ($)" />
<input name="expenses" id='expenses' type="text" placeholder=" Expenses ($)" />
<input name="sell" id='sell' type="text" placeholder=" Selling Price ($)" />
<input name="selldate" id="datepicker" type="text" placeholder="/Pick Date Sold" />
<input name="seller" id='seller' type="text" placeholder="/Pick Salesman" />
<button type="input" class='ajaxbutton' onClick="parent.process();">Enter Details</button>
<button type="input" class='ajaxbutton' onClick="parent.home();">Close</button>

</div>
<div id='morelabels'>
<label for="workdone">Expenses</label>
<textarea name="workdone" id="workdone" placeholder=" details of expenses"></textarea>
</div>
<div id='moreentries'>
<label for="comments">Comments</label>
<textarea name="comments" id="comments" placeholder=" any comments"></textarea>
</div>
</form>


function process()
{
carreg =  window.frames[0].document.getElementById('registration').value;
if (carreg=="") {
alert('Registration is a required field');
return;
}
yearstr=window.frames[0].document.getElementById('year').value;
yearint=parseInt(yearstr);
var d = new Date();
var this_year= d.getFullYear();
if(yearint>this_year)
{
alert('stuffed');
return;
}
alert('ok so far');
}

0
Comment
Question by:cookers
  • 5
  • 3
  • 2
10 Comments
 
LVL 14

Expert Comment

by:Kalpan
ID: 36813556
seems like it is not using the javascript function having the

<button type="input" class='ajaxbutton' onClick="parent.process();">Enter Details</button>

Please verify with elements error with mozilla firebug or IE inspect element tool
0
 

Author Comment

by:cookers
ID: 36813583
kalmax, I checked using bad data and the alerts are fired so it is calling that function
0
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36813640
You mean if validation fails, still form submits? If yes then Try like this

function
function process()
{
  carreg =  window.frames[0].document.getElementById('registration').value;
  if (carreg=="") {
  alert('Registration is a required field');
  return false;
  }
  yearstr=window.frames[0].document.getElementById('year').value;
  yearint=parseInt(yearstr);
  var d = new Date();
  var this_year= d.getFullYear();
  if(yearint>this_year)
  {
  alert('stuffed');
  return false;
  }
  alert('ok so far');
  return true;
}

Open in new window


html
<button type="input" class='ajaxbutton' onClick="return parent.process();">Enter Details</button>

Open in new window

0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 14

Expert Comment

by:Kalpan
ID: 36813683
does it displays alert('ok so far'); if everything works with process function ?
0
 

Author Comment

by:cookers
ID: 36813823
kalmax, yes it does display 'OK so far',
sonawanekiran: I did this
I did this

function process()
{
carreg =  window.frames[0].document.getElementById('registration').value;
if (carreg=="") {
alert('Registration is a required field');
return false;
}
yearstr=window.frames[0].document.getElementById('year').value;
yearint=parseInt(yearstr);
var d = new Date();
var this_year= d.getFullYear();
if(yearint>this_year)
{
alert('stuffed');
return false;
}
alert('ok so far');
return true;
}

and this

<button type="input" class='ajaxbutton' onClick="return parent.process();">Enter Details</button>

and still it processes the form...bummer hey?

0
 
LVL 17

Accepted Solution

by:
sonawanekiran earned 500 total points
ID: 36813851
If you want submit form then return true  otherwise return false
If you reach alert('ok so far'); then above code will submit the form
If you reach either alert('stuffed'); OR  alert('Registration is a required field'); then form will not be going submit.
0
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 36813855
OR show your link
0
 

Author Comment

by:cookers
ID: 36813862
If I take out the form action and leave
<form name="cwccars" id='cwccars'>
it still blanks the form values after a few seconds after validation
0
 

Author Comment

by:cookers
ID: 36813902
sonawanekiran: your answer is correct, it does what I want but for technical reasons can you explain why it submits the form at all as I dont have "submit" anywhere iin my scripts or button type?
0
 

Author Closing Comment

by:cookers
ID: 36813905
Still confused
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question