Reputation: 1627
I am facing an issue in IE7 only while passing an a dynamic value to javascript. as shown below. this work in all browsers except IE 7.
$val =$id.$i;
echo "<a href='javascript:void(0);' id='network' class=$val value='$octet'>+".$octet.".0.0.0</a> <br />";
I am capturing this value in javasript as show below
$(".msg_body #network").click(function(){
var network = $(this).attr('value');
alert(network); // alert fails in IE 7
var clsName = $(this).attr("class");
alert(clsName); // alert fails in IE 7
complete php code below
<?php
$octets = $this->Ip;
$octetets = $this->octent1;
$i= 1;
$id='network';
foreach($octetets as $octet){
$val =$id.$i;
echo "<a href='javascript:void(0);' id='network' class=$val value='$octet'>+".$octet.".0.0.0</a> <br />";
value='$octet'>+".$octet.".0.0.0</span> <br />";
$i++;
}
?>
Upvotes: 0
Views: 128
Reputation: 3936
element Id's must be unique, so instead of using that attribute, use another like name:
Alter your php:
<?php
$octets = $this->Ip;
$octetets = $this->octent1;
$i= 1;
$id='network';
foreach($octetets as $octet){
$val =$id.$i;
echo "<a href='javascript:void(0);' name='network' class=$val value='$octet'>+".$octet.".0.0.0</a> <br />";
value='$octet'>+".$octet.".0.0.0</span> <br />";
$i++;
}
?>
and your jQuery:
$(".msg_body").on('click', '@network', function(e){
e.preventDefault();
var network = $(this).attr('value');
alert(network); // alert fails in IE 7
var clsName = $(this).attr("class");
alert(clsName); // a
});
Upvotes: 0
Reputation: 87073
Try this:
$(".msg_body").on('click', '#network', function(e){
e.preventDefault();
var network = $(this).attr('value');
alert(network); // alert fails in IE 7
var clsName = $(this).attr("class");
alert(clsName); // a
});
Upvotes: 1