Jump to content

selector - type input/checkbox/select


Destramic

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

Archived

This topic is now archived and is closed to further replies.

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