Solved

Problem with html form processing

Posted on 2011-09-29
10
324 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
Comment Utility
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
Comment Utility
kalmax, I checked using bad data and the alerts are fired so it is calling that function
0
 
LVL 17

Expert Comment

by:sonawanekiran
Comment Utility
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
 
LVL 14

Expert Comment

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

Author Comment

by:cookers
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 17

Accepted Solution

by:
sonawanekiran earned 500 total points
Comment Utility
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
Comment Utility
OR show your link
0
 

Author Comment

by:cookers
Comment Utility
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
Comment Utility
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
Comment Utility
Still confused
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

762 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now