Jump to content

Javascript to replace contents of one field with another

Recommended Posts

Hi i'm a newbie to scripting of any sorts and i have a problem i'm trying to replace a text field on a submission form based on the contents of another field (dropdown), with the contents of either of two other text fields.

In essence if the contents of one field "Name_Type" equal "Muscle Group" then I want the field "Workout_Name" to equal the contents of the Muscle_Group_id field, likewise if the contents of field "Name_Type" equal "Workout_Type" then I want the field "Workout_Name" to equal the contents of the Workout_Type_id field. If neither is the case then I want the contents of the field "Workout_Name" to stay as it is.

If had an attempt at scripting this which I placed in the footer of the submission datapage but without success, can anyone help?


function replace ()

var name_type = document.getElementById("InsertRecordName_Type").value;
var muscleG = document.getElementById("InsertRecordMuscle_Group_id").value;
var workType = document.getElementById("InsertRecordWorkout_Type_id").value;
var work_name = document.getElementById("InsertRecordWorkout_Name").value;

if (name_type = "Muscle Group") {

     var Work_nameSubmit = muscleG;

          else if (name_type = "Workout Type") {

              var Work_nameSubmit = workType;
                    else {
                       var Work_nameSubmit = work_name;


Link to comment
Share on other sites

I have trouble with the onsubmit function in Caspio.

Maybe try onfocus or onenter on the element you want the values to go in to; so this script runs prior to Submit.

A good tip for building and testing js is to drop in alerts

document.getElementById("caspioform").onsubmit= alert('hi');


document.getElementById("ElementToReplace").onenter = alert('hi');


if (name_type = "Muscle Group") {

     alert('name_type is Muscle Group');

     var Work_nameSubmit = muscleG;


Hope this helps

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.

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.


  • Create New...