If {fild name} = “this” do that

mabeach 09 Feb, 2012
I am trying to get a form to post an alert if fildname = something. I am not sure how to go about this.

Should I use java or php???

Where do I put the code???



var r={fildname};
if (r==this)
  {
 alert( “message”);
  }
else
  {
 document.write ( “Have a good day!”);  }
}



Thanks for the help.
:mrgreen:
GreyHead 10 Feb, 2012
Hi mabeach,

You need to use JavaScript (neither Java nor PHP).

If your input has id='fildname' then you can use code something like this in a Load JS action:
window.addEvent('domready', function() {
  var fildname = $('fildname');
  fildname.addEvent('change', function() {
    if ( fildname.value == 'xxxx' ) {
      alert('message');
    }
  });
});
You may need to find someone to help with the exact JavaScript that you need.

Bob
mabeach 10 Feb, 2012
Thanks for the reply.

I am still not have any luck.
I did some testing and I am not getting the fild name. I added the code to the JS load and put that in the submit button, so this will show up before the user gets to the thank you message.

Here is the test I did:

var x == $(fildname);
alert(x);


I do get the alert but the text is null.

Any idea?
GreyHead 10 Feb, 2012
Hi mabeach,

I don't understand what this line is supposed to be??
var x == $(fildname);
It looks as though you are making up code here.

You may need to find someone to help with the exact JavaScript that you need.

Bob
mabeach 10 Feb, 2012
I am a bit new to javascript. Sorry.

I want to
set var to x
make x = fildname
alert(x);

alert("TEST: " + document.forms["FORMNAME"]["fildname"].value);


but still not work.

Can you tell my how to grab the fildname from a form in a var after I hit submit?
polderguy 12 Feb, 2012
mabeach,

Please compare you line of code:

var x == $(fildname);


with the line from Bob's example code:

var fildname = $('fildname');


and then make the necessary 3 changes.

PolderGuy
mabeach 13 Feb, 2012
I did some more testing and I am unable to get the var. Here is the test I ran.

//I don't think this is getting the VAR right
var fildname = $('input_radio_18'); 
if (fildname == x)
  {
//This is  = NULL  
  alert(fildname); 
  }


This is the code I want to work.

//This is the code I want to work.
var fildname = $('input_radio_18'); 
if (fildname == 'some test')
  {
  alert("You have picked a Tour. Please contact the team to discuss details."); 
  }
polderguy 14 Feb, 2012
mabeach,

Please compare your line of code:

if (fildname == x) {


with Bob's:

if ( fildname.value == 'xxxx' ) {


and again make 3 changes.
You're getting closer ...

PolderGuy
mabeach 14 Feb, 2012
Did some more testing with this code below--with no luck. I know this code is not getting the var right...so what am I missing?


var fildname = $('input_radio_18'); 
if (fildname.value == 'text')
  {
  alert("You have picked a Tour. Please contact the team to discuss details."); 
  }
GreyHead 14 Feb, 2012
Hi mabeach ,

That code looks like good JavaScript.

Use your preferred web developer tools (F12 in IE8 or IE9, Shift+Ctrl+I in Chrome, FireBug in FireFox, DragonFly in Opera) to check what the value of fildname.value is. That will help you to know what needs to be fixed next.

Bob
mabeach 14 Feb, 2012
I am running chrome. I looked with the console on the form page and

fildname.value = undefined

Also on the result page fildname = null.
GreyHead 14 Feb, 2012
Hi mabeach,

It will be undefined until the snippet runs. What is the value of $('input_radio_18')?
Bob
mabeach 14 Feb, 2012
That is the name of the fild id of the Radio Box.

The console gave me this. I think I am doing it wrong.

document.write $('input_radio_18');
SyntaxError: Unexpected identifier



But if i do this.

document.write ('input_radio_18');

it = input_radio_18


How should I test this?
mabeach 15 Feb, 2012
I fixed it:
I added this to the Form tag attachment sections.


onsubmit="if(document.forms['FormName']['InputName'][0].checked) { alert('Text to display'); }"


Thanks for the help.
This topic is locked and no more replies can be posted.