Jump to content

Conditional javaScript question


Recommended Posts

On my Submission form, I have a field (Customer field) that needs to be populated with another field (New Customer Field) if the "Customer field" has the words "01 New Customer" in it.

Here is the latest code I've tried (in the footer of the form), but so far my JavaScript is not working. Can anybody guide me in the right direction?

var o_Cust1 = document.getElementById("InsertRecordCustomer");

var o_CustNew = document.getElementById("InsertRecordNew_Customer");

function fun_conditional()

if(o_Cust1.value="01 New Customer")

{

o_Cust1.value=o_CustNew.value;

}

window.onsubmit = fun_conditional;

Link to comment
Share on other sites

there's nothing wrong on your script, I just want to add this tip here for your info because I've been using this to one of my site with the topic modern decorative clocks.

Create Text Files To Link To Your Web Pages

First, you'll have to create a new text file that contains the HTML code you want to reuse. Then, you'll use JavaScript to call the information in that external file. The text and images in the external file will load just as if they were part of the Web page.

Step 1: Open Notepad or any text editor.

Step 2: Type in the HTML code you want to include in the file, with proper formatting. You may already have existing code that you can just cut and paste into the text editor.

Copyright 2001, NetMechanic Inc.

All Rights Reserved

Step 3: Remove all the line breaks in the code. It must all be on one line or you'll get a JavaScript error on your page instead of copyright information.

Copyright 2001, NetMechanic Inc.

All Rights Reserved

This code may display on multiple lines in this newsletter story. Since the line is relatively long, your browser wraps the text just like it does in the rest of the story text. Just be absolutely sure it shows on a single line in your Notepad file.

Step 4: Enclose the HTML code inside a document.write statement. Be sure to place the HTML text inside single quotes

document.write('

Copyright 2001,

NetMechanic Inc.

All Rights

Reserved

')

You don't need to change any of the HTML code, just place it inside the JavaScript statement.

Careful using single quotes inside your text string. Always place a "\" in front of the single quotation mark. Otherwise, JavaScript will think you're trying to close the string prematurely and give you an error message.

Step 5: Save the file as a .txt file. We used "footer_no9.txt" as our file name.

If you wanted to insert a page header too, you'd just follow the same steps and insert the text and graphics you want as your page header. We used the following code and saved the file as "header.txt"

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

Good news, problem solved. The trick was to look at the source code from Caspio; since this was a drop-down calling data from another table, it was an options call.

Here is the working solution:

function init() {

var form = document.getElementById('caspioform');

form.onsubmit = function() {

return processForm();

}

}

function processForm() {

var form = document.getElementById('caspioform');

var o_Cust1 = document.getElementById("InsertRecordCustomer");

var o_CustNew = document.getElementById("InsertRecordNew_Customer");

if(o_Cust1.value == "Add New Customer")

{

o_Cust1.options[0] = new Option(o_CustNew.value, o_CustNew.value, false, true);

}

else

{

o_Cust1.value = o_Cust1.value;

}

return true;

}

window.onload = init;

-------------------------

However now I have a new problem with another database.

Same scenario except it uses cascading dropdowns. I opened a new question on the baord. Any help?

Look for question: JavaScript getElementsByName, cascading drop box problem

I cannot seem to get the getElementsByName to work for me.

Thanks, TDW

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...