Jump to content

I need a little HTML help :(

Bobbincat

Hey guys ,

so i have a task at school to :

 

Add a set of radio buttons to the form to accept a level of entry such as GCSE, AS or A2. Write a
function that displays the level of entry to the user in an alert box so that the level can be confirmed
or rejected.
 
iv done the radio buttons because its easy but if someone could show me the code for alert box implimentation that would be amazing.
thanks
 
felix
Link to comment
Share on other sites

Link to post
Share on other sites

In the radio buttons you could add

<input type="radio" name="lvl" value="lvl" onBlur="JSAlert('radiobuttonlvl');"><script>JSAlert = function(lvl){	alert("Are you sure you are in " + lvl + "?");}</script> 

I'm not sure if you're familiar with JS, so I'll break it down a bit. If you are, soz.

 

You add an "onBlur" event to your radio button. "onBlur" activates once you click or tab away from or otherwise leave the radio button. So if you click away from the radio button or click the submit button or something, then the "onBlur" activates. Underneath our code between script tags we have the javascript that handles the Alerting. 

 

To do  this we're creating a function and passing a variable to that function for a more dynamic feel. You'll notice above that in the onBlur we have a "JSAlert" function, in between the brackets is the variable we're passing to the javascript function. This should be the alert level (AS, A2 etc).

 

We set JSAlert to equal our alerting function. In the function brackets we have "lvl". This is a parameter that we're getting from the radio button, what is between the onBlur function brackets. Inside the curly braces we have our alert.

 

The code for alerts is actually really simple. Put the text you want inside quotation marks. Then we have to get that variable to be included in the message that gets displayed to the user. As you can see, to do this we close off the quotation marks, add a '+' sign and then the function parameter, which is "lvl" in this case, then a second '+' sign to tell it we want to go back to writing text again.

 

That should just about do it, normally I wouldn't go to the trouble of explaining, but since this is for your school work..... You should probably know what's going on.

 

EDIT: After some extra thought, seeing as it is a radio button, you can just as easily switch "onBlur" to "onClick" to have the alert display as soon as the user clicks the radio button. Also, your question description mentions confirming or rejecting. 'Alert' only has one button, the 'OK' button. You may find that using a 'confirm' may suit your task better. This gives two buttons, 'OK' and 'Cancel'. To change from an alert to a confirm, replace "alert" with 'confirm'

I am good at computer

Spoiler

Motherboard: Gigabyte G1 sniper 3 | CPU: Intel 3770k @5.1Ghz | RAM: 32Gb G.Skill Ripjaws X @1600Mhz | Graphics card: EVGA 980 Ti SC | HDD: Seagate barracuda 3298534883327.74B + Samsung OEM 5400rpm drive + Seatgate barracude 2TB | PSU: Cougar CMX 1200w | CPU cooler: Custom loop

Link to comment
Share on other sites

Link to post
Share on other sites

Hello Bobbincat,

 

Id first of all like to wish you good luck to your courses for school. Here is the JS code you need to make a popup box.

 

alert("Text goes here :)");

 

If you require any other help please feel free to contact me via my profile or through this post :)

 

~ Harry

It seems impossible until it's done.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×