im new to codeginiter and its developing. i used dropbox (html select box) when i pressed option there. i need to trigger a alert box.in oder to do that i used following code. But it didnt work on me. and i could find the mistake i've done please help me.
<html lang="en">
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<title>Ask Questions</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link href="<?php echo base_url(); ?>css/bootstrap.min.css" rel="stylesheet">
<link href="<?php echo base_url(); ?>css/style.css" rel="stylesheet">
<script type="text/javascript" src="<?php echo base_url(); ?>js/jquery.min.js">
// untill select catogory tags are disabled
function activate_match()
{
// var tnmt_id = "hip hure";
alert("tested");
//Get the id of the tournament selected in the list
}
</script>
</head>
<body>
<div class="container">
<p class="help-block">
How to Ask </br>
Is your question about DIY ? </br>
We prefer questions that can be answered, not just discussed.<br>
Provide details. Share your experience. </br>
</p>
<div class="form-group">
<?php
echo form_open('homepage/askquestionview');
echo validation_errors();
?>
</div>
<p> </p>
<div class="form-group">
<select name="cat" id="cat" onchange="activate_match()">
<?php
foreach($catogories as $cat) {
echo'<option value="' . $cat . '">' . $cat . '</option>';
}
?>
</select>
</div>
<div class="form-group">
<p>
Description: <br/>
<textarea name="decription" rows="5" cols="100"> </textarea>
</p>
</div>
<p></p>
<div class="form-group">
Declare new Tags:<br/>
<input type="text" value="" name="tag">
</p>
</div>
</div> <p>
<input type="submit" class="btn btn-success btn-block" value="Post Your Question" id="postQuestion">
</p>
<?php echo form_close(); ?>
</body>
</html>
You need to have two separate script
tags:
<script src="<?php echo base_url(); ?>js/jquery.min.js"></script>
<script>
function activate_match() {
// var tnmt_id = "hip hure";
alert("tested");
//Get the id of the tournament selected in the list
}
</script>
If script
has src
attribute its inner content is ignored. So the first script is to load jQuery, and the second to declare you functions.
You should not be using inline javascript. Since you have jQuery available this should do the trick:
$(document).ready(function(){
$('#cat').change(function(){
alert('Tested! Current select value is: ' + $(this).val());
});
});
Also, it is required to use separate script tag for your custom code, and separate for including files - you have embeded your function inside jQuerys script tags and thats why it is not working.
change in html
<select name="cat" id="cat" onchange="activate_match(this.value)">
<?php
foreach($catogories as $cat) {
echo'<option value="' . $cat . '">' . $cat . '</option>';
}
?>
</select>
In your script
<script type="text/javascript" src="<?php echo base_url(); ?>js/jquery.min.js"></script>
<script>
// untill select catogory tags are disabled
function activate_match(id)
{
// var tnmt_id = "hip hure";
alert(id);
//Get the id of the tournament selected in the list
}
</script>