Solved

Problem with html form processing

Posted on 2011-09-29
10
332 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Save ms data to server side. 19 56
how to debug htl and js pages 8 39
key press alert 2 32
Change static entered data to dynamic with counter 5 15
Find out what you should include to make the best professional email signature for your organization.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

808 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