• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

javascript form submit

New Here ,
Feb 08, 2007 Feb 08, 2007

Copy link to clipboard

Copied

Hi i am using javascrpit to submit my form with the code below, but because i have a cfoutput query in the form it is submiting all form elements i need it to submit the current record the submit btn is on ie
<form>
<cfoutput query>
Record1 Submit
Record2 Submit
Record3 Submit
</cfoutput>
</form>
so if record 1 submit was click only that record would get submitted to the action page
full code below
TOPICS
Advanced techniques

Views

828

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 08, 2007 Feb 08, 2007

Copy link to clipboard

Copied

no, it has nothing to do with <cfoutput>. it will submit all form elements because they are all in one form. it is the FORM that is submitted, not individual elements of a form.

separate your 3 records into separate forms to submit them individually, or give each submit button a unique name and then in the from processing script check which submit button was clicked and process only corresponding record's value.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 08, 2007 Feb 08, 2007

Copy link to clipboard

Copied

Hi so if i have
<a href="javascript:not_used()">SUBMIT DISCOUNT</a> and i want to add #GetCust.CustomerID# to this value, so it submits this record, how would i do it?

i have this javascript code as well
<script language="javascript">
<!--
function not_used() {
var answer = confirm ("THIS WILL UPDATE CUSTOMERS DISCOUNT & \nSEND THE CUSTOMER AN EMAIL WITH THERE LOGIN DETAILS")
if (answer)
window.document.form3.submit();
}
//-->
</script>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 08, 2007 Feb 08, 2007

Copy link to clipboard

Copied

i think in your case it will be easiest to have a separate form for each of your records, ie switch around <form...> and <cfoutput> so that your <form...>...</form> is inside the <cfoutput> tag. also change your submit link to a submit button with an onclick event calling your javascript. that way you will only submit one record and it will be easy for you to process it on the action page.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 08, 2007 Feb 08, 2007

Copy link to clipboard

Copied

ok thanks i have done that but now get a javascript error do i have my onclick right?

<input type="button" onClick="javascript:not_used()">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 08, 2007 Feb 08, 2007

Copy link to clipboard

Copied

remove javascript: from the onClick and put ; after not_used()

<input type="button" onClick="not_used();">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 08, 2007 Feb 08, 2007

Copy link to clipboard

Copied

oh, and better change the call and your function to:
call:
<input type="button" onClick="not_used(this.form);">

function:
function not_used(objForm) {
var answer = confirm ("THIS WILL UPDATE CUSTOMERS DISCOUNT & \nSEND THE CUSTOMER AN EMAIL WITH THERE LOGIN DETAILS");
if (answer){
objForm.submit();
}
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 08, 2007 Feb 08, 2007

Copy link to clipboard

Copied

ok done that but i now get a javascript error, the popup dosent appear?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Feb 08, 2007 Feb 08, 2007

Copy link to clipboard

Copied

LATEST
hmm...
ok, change your code to the following (tested and working):

function: (note: this is a new function - replace your old one with this one)
function checkAnswer(objForm){
if (confirm("THIS WILL UPDATE CUSTOMERS DISCOUNT & \nSEND THE CUSTOMER AN EMAIL WITH THERE LOGIN DETAILS")){
return true;
} else {
return false;
}
}

function call:
NOTE: the call is moved to an onSubmit event of the form, so what you need to do is:
a) change your <input type="button" onClick="not_used(this.form);"> to
<input type="submit" name="submit" value="Update" />

b) change your <form... > to
<form method="post" action="InsertDiscount.cfm" onSubmit="return checkAnswer(this);">

now it will work as you want it to.

cheers

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation