1

Im doing an assignment where I have to create a form where the user can enter multiple values... values in a text box as well as choosing 1 option from a radio button. I need to create an alert that shows the user their choices.. I have found a way to create an alert but it only allows me to 1 value... see below

    var username=document.getElementById("yourname").value;
    var toAlert="Thank you "+username;
    toAlert=toAlert+", have a good day";
    alert(toAlert);

but like I said, it need the alert to indicate multiple values. Simply adding additional "+blahblah" does not work... I hope this question makes sense...

I also need to know how I can get the user's radio button selection in the pop up as well...

1 Answers1

0

create field called e.g. secondfield

 var username=document.getElementById("yourname").value;
 var secondfield=document.getElementById("secondfield").value;
 var toAlert="Thank you "+username+", have a good day. Second field: "+secondfield;
 alert(toAlert);
Jerzy Zawadzki
  • 1,975
  • 13
  • 15
  • I got this message when adding my second field [objectHTMLInputElement] – user2626641 Jul 28 '13 at 00:25
  • @user2626641 that is what happens when the DOM _Object_ reference for an `` is converted to a _String_; you don't want the reference to the _Object_ as your _String_; you want it's _value_. – Paul S. Jul 28 '13 at 00:27
  • as Paul S. said but simplier: you propably missed `.value` on your second field – Jerzy Zawadzki Jul 28 '13 at 00:28
  • you were indeed correct :) thanks so much.... does it work the same for radio buttons.... the user can choose between 3 options on a radio button, i also want this to display in my popup – user2626641 Jul 28 '13 at 00:32
  • here you have how to get value of radio button (first answer/javascript part) http://stackoverflow.com/questions/9618504/get-radio-button-value-with-javascript – Jerzy Zawadzki Jul 28 '13 at 00:33
  • I dont understand.... so am I able to alert the user to their radio button selection as well? Upon trying to add a third value to my alert I find it does not work! – user2626641 Jul 28 '13 at 01:49