Jump to content

Concatenating two fields in an update form


Recommended Posts

I took my js directly from forum site and I can't seem to make it work. My alert does not work either.

The two fields I am concatenating are both regular dropdowns (not cascading). The field I want to update them to is not display only - it is text.

All of my field names are entered correctly.

Here is my script. Very straightforward. I got this to work on my input form, just can't get it to work on the update form. Any help would be appreciated.

function concatenate()

{

var position1 = document.getElementById("EditRecordHauler").value;

var position2 = document.getElementById("EditRecordDestination").value;

var allpositions = position1+"|"+position2;

document.getElementById("EditRecordHaulerDestination").value = allpositions;

alert('all positions='+allpositions);

}

document.getElementById("caspioform").onsubmit=concatenate;

Link to comment
Share on other sites

Try this:

function concatenate()

{

var position1 = document.getElementById("EditRecordHauler").options[document.getElementById("EditRecordHauler").selectedIndex].value;

var position2 = document.getElementById("EditRecordDestination").options[document.getElementById("EditRecordDestination").selectedIndex].value;

var allpositions = position1+"|"+position2;

document.getElementById("EditRecordHaulerDestination").value = allpositions;

alert('all positions='+allpositions);

}

document.getElementById("caspioform").onsubmit=concatenate;

Please let me know if it works for you.

Cheers :wink: :wink: :wink:

Link to comment
Share on other sites

If you don't even get the alert working it means there are broken codes prior to the alert line, when browser get to the broken code it stops rendering and compiling the rest. I suggest if you start debugging the code by having the alert command at the beginning of the script, if it does not work then other part of your page has broken codes. You can use Firefox add-on called Firebug for the debug purpose.

Keep us updated. You may also provide the URL, I can take a look.

Best,

Bahar M.

Link to comment
Share on other sites

By moving the alert statement up and working my way down I was able to get it to work with trial and error. It turns out that I needed to use getElementsByName for both of the dropdowns. I was thinking that syntax was only needed for cascading dropdowns. Anyway...I got it and here is the code.

function concatenate()

{

var position1 = document.getElementsByName("EditRecordHauler")[0].value;

var position2 = document.getElementsByName("EditRecordDestination")[0].value;

var allpositions = position1+" | "+position2;

document.getElementById("EditRecordHaulerDestination").value = allpositions;

}

document.getElementById("caspioform").onsubmit=concatenate;

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...
 Share

×
×
  • Create New...