Jump to content

Recommended Posts

hey guys im trying to get the correct alert when the form is being used....for instance if a user changed the input value i want it to alert input...if checkbox is checked alert checkbox....and the same with select if option is selected

 

but all i get is the script alerting input anytime i do anything to any field can someone please help me on how to divide these fields apart from each other....thank you

 

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="js/library/jquery.js"></script>
<script type="text/javascript" src="js/library/jquery.cookie.js"></script>
<style>

div 
{
display : inline;
}
</style>
</head>
<body>
<script>	
$(document).ready(function()
{	
function remember_field_value(selector)
{
	$(selector).change(function() 
	{		
		if ($(selector + ':checkbox'))
		{
			alert('checkbox');
		}
		else if ($(selector + ':input'))
		{
			alert('input');
		}
		else if ($(selector + ':selected'))
		{
			alert('select');
		}
	});
}

remember_field_value('input#game_type1');
remember_field_value('input#tester');
remember_field_value('select#game');
});
</script>
<form method="post">
<input id="game_type1" name="game_types[]" value=""/>
<input id='tester' type="checkbox" name="team" value="other">
<select id='game'>
<option>hello</option>
<option>bye</option>
</select>
<input type="submit" value="Submit">
</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/230507-selector-type-inputcheckboxselect/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

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

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.