Error 80020101 on .val() [duplicate] - php

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Could not complete the operation due to error 80020101. IE
I'm facing a little problem with my jQuery code.
I have a first page with some fields like :
[Code 1] [Code 2] [Code 3]
The user type something in one of the input, I get the result that I load in another page with .load method. Here's the code :
$(function() {
$("#code_cip").autocomplete({
source: tab,
minLength: 6,
delay: 1000,
select: function(event, ui) {
var selectedObj = ui.item;
$("#code_cip_ind").val(selectedObj.value);
$("#test").load("test.php?id="+selectedObj.value);
}
});
});
This, works great. It correctly load the "test.php" page with the good values.
BUT... In the test.php page I have a form, and I try to fill it like this :
test.php :
<?php
$gest_medecin = new gest_medecin($db);
$medecin = $gest_medecin->returnValues();
$adresse = $medecin->Adresse;
echo $adresse // This, output the good value of the attribut
?>
<script>
adresse = <?php echo $adresse;?>;
alert(adresse);
$("#adresse").val(adresse);
</script>
<input name="adresse" id="adresse" type="text" />
The problem is :
When I try to alert the "adresse" var, or use it with my .val method, I get the error 80020101 in IE, and in Firefox, nothing is happening...
I tried to fill the variable with some test string like this :
adresse = <?php echo "123456" ?>
And that works great...
As mentioned I checked that the $medecin->Adresse was correct with my echo and it is. It contains something like "word1 word2"
I really have no clue why my code isn't working...
Any help ?

Always look at the final result to spot the error.
You are missing quotes around
adresse = "<?php echo $adresse;?>";
strings always need quotes.
it worked with 123456 because that is an integer value that needs no quotes.
Firefox will tell you this in its error console with a better error message.

Related

Issue with displaying PHP code in HTML

I am using a slider in one HTML page and sending its value to the next page using a hidden textbox like this :
Page1.html
<script type="text/javascript">
var flowPercent = document.querySelector('#flow');
function sliderFunc()
{
var f = function(){
var x = flowPercent.value;
window.open('Page3.html?val=x','_parent');
};
f();
};
</script>
And then I would like to display this in the next HTML page using PHP echo like this :
<?php
$val=$_POST['val'];
echo "Value is $val";
?>
But neither the value nor "Hello" is being displayed. Why is this ?
How do I fix this ?
Thanks !
If your PHP-Code is contained in Page3.html, that page should have a .php-extension in order to execute the code. And also you are not posting anything, so $_POST will be useless...
Try window.opener.getElementById('textbox') instead to query the value...
Just change your page3.html to page3.php because you can't use php code in html file but you can use html code in php

Save JavaScript array to server using PHP

I have recently started coding with javascript/php using the Cloud9 IDE.
I know this may be a duplicate of some questions on here, but I have yet to find a solution that works for me.
I have an array of custom javascript objects that I would like to save to a file on the server (later to be retrieved to repopulate data on the page):
<script>
var questionList = [];
function saveToFile() {
var x =JSON.stringify(questionList);
$.post("saveQuestion.php", {data : x}, function(){alert("File saved successfully")});
}
</script>
//in the body of the html
<button id="saveToFileButton" type="button" onclick='saveToFile()'>Save to file</button>
The php file 'saveQuestion.php' is in the same directory, and is as follows:
<?php
$data = $_POST['data'];
file_put_contents("savetest.txt", $data);
?>
However, despite my best efforts, 'savetest.txt' remains empty.
I know that 'x' is being assigned the correct value as I can print it out to a html element.
Edit: The php script has permission to write to the file, but as far as I can tell it is never called. What would be a possible cause/solution to this?
Can someone offer a simple explanation that highlights what I am doing wrong and possible ways to fix it?
Thanks!
Maybe you should assign the questionsList array some values:
<script>
// Check if your assigning a value to this array
var questionList = ['value 1', 'value 2', 'etc..'];
function saveToFile() {
var x =JSON.stringify(questionList);
$.post("saveQuestion.php", {data : x}, function(){alert("File saved successfully")});
}
</script>

accessing local var value from JS function in PHP

After searching for internet and even here for 5 hours, i am still stuck at getting value of a local variable in a function and sending it to PHP.
I have tried different syntaxes but none of them seems to be working. This code below, takes an input field from PHP and assign some value to it (having problem send this value back to PHP)
$(document).ready(function() {
//select all the a tag with name equal to modal
$('form[name=modal]').click(function(e) {
//Cancel the link behavior
e.preventDefault();
//Dont go until value is not 7
console.log('i am Now waiting for input');
var s = $('#serial').val();
console.log('searching for ' + s);
while(s.length != 7) return;
//When code value reaches 7
var code = $('#serial').val();
console.log('Value is reached ' + s);
});
});
In PHP
echo "<script>document.write(code);</script>";
Uncaught ReferenceError: code is not defined
please help
You should do somthing like this in javascript when $('#serial') is your input field.
$.ajax({'url':'your_php_file_url', 'type':'post', 'data':{'str':$('#serial').val()}}).done(function(data){
console.log(data.code);
});
And in php
$output = Array('code' => 'not set');
if (isset($_POST['str']))
{
//do your search and assigne value to output
$output['code'] = 'some value';
}
echo json_encode($output);
In short - you send your search string via ajax to php and make your searches. Then you echo it out as json, then ajax will read it as an object and you can use those values you want.
ok, i have almost tested every possible solution but all in vain... so i am off and try to use some normal method rather than javascript. Thanks for all your answers guys.

autocomplete plugin not passing values in php jquery

I am using a autocomplete
http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/
And below i have two pages index.php and ajx_page.php
index.php
<form name="send_coup_ajx_form" id="send_coup_ajx_form" method="post">
<select name="member_type" id="member_type">
<option value="customer_type">Customer</option>
<option value="BPartner_type">Business Partner</option>
</select>
<input type="text" name="sel_rad" id="resultant_text" />
<input type="submit" name="submit" value="go" />
</form>
<script type="text/javascript">
$(document).ready(function(){
$("#resultant_text").autocomplete("ajx_page.php", {
width: 260,
matchContains: true,
//mustMatch: true,
//minChars: 0,
//multiple: true,
//highlight: false,
//multipleSeparator: ",",
selectFirst: false
});
});
</script>
And below code for
ajx_page.php
<?php
$select_type = $_GET['member_type'];
$type = $_GET['sel_rad'];
?>
when i type in the textbox, it gives me an error as
Notice: Undefined index: member_type in ajx_page.php on line 2
That means member_type is not going in that page..
And when i comment all this code and put the below code in ajx_page.php
<?php
echo "Name1\n";
echo "Name2\n";
echo "Name3\n"
?>
It displaying autocomplete feature list. but when i want to get the value of that object member_type it is saying an error..
so how do i pass additional values using this autocomplete plugin
I have added an Image to overwriting problem to #veeTrain
I'm not sure if the autocomplete plugin is intended to handle this type of scenario or not.
However, if you want to manually pass these values into your php script, then it would be pretty simple (at least in this scenario where you are only trying to send two fields in).
var memberType = $("#member_type>option:selected").val();
var selRad = $("#resultant_text").val();
$("#resultant_text").autocomplete("ajx_page.php?member_type="+memberType+"&sel_rad="+selRad, {
//...
But this probably isn't the answer answer you're looking for.
Update: I'm glad that syntax for sending the values is working for you.
It looks like you have overlapping ids being printed out -- is that what you mean by 'bold'? Apparently you aren't using the correct delimiter for creating a second auto-complete suggestion. I'm not sure what the autocomplete handler is wanting to delineate between items. Undefined is probably showing up because one of your items couldn't be found. You should use your browser's Developer Tools to debug what is getting sent.
Also, if you wanted the option's text rather than the value then you'll need to access the .text() rather than the .val() of the select drop down.
Update: This post might have something to say about what autocomplete is expecting.
I think to pass in additional parameter for bassistance's autocomplete, the only way is to modify the autocomplete.js file. I did something similar before, but the method is quite hardcoding. Posted below for your reference (it's around line 376):
$.ajax({
// try to leverage ajaxQueue plugin to abort previous requests
mode: "abort",
// limit abortion to this input
port: "autocomplete" + input.name,
dataType: options.dataType,
url: options.url,
data: $.extend({
member_type: ($("#member_type").length != 1)?$("#member_type").val():-1,
q: lastWord(term),
limit: options.max
}, extraParams),
success: function(data) {
var parsed = options.parse && options.parse(data) || parse(data);
cache.add(term, parsed);
success(term, parsed);
}
});
I only added one line to the original code, at line 10: member_type: ....
Take note that I pass in "-1" if the object is not found on that page to prevent javascript error.
Hope it helps!

PHP error and JavaScript validation

I have an error in my PHP on this line:
var strRooms = <?=$js_var?>;
It is saying that this has an invalid markup, what does this mean?
You can look at the application here: application
Now if you type in nothing in the textbox, then it doesn't display a message saying "Please Enter in a Room Number", if you type in a invalid room number then it doesn't show a message stating "This Room is Invalid". Why is it not working?
I know the code doesn't work in jsfiddle but I have included my code in the jsfiddle so that you can see the whole code and the way it is laid out. jsfiddle
So how can this error be fixed and how can the JavaScript validation message appear as they should do?
var strRooms = <?php echo json_encode($js_var); ?>;
This will guarantee that it'll work, regardless of what type of variable $js_var is.
Try this var strRooms ="<?php echo $js_var; ?>";
Have you tried quotes?
var strRooms = "<?=$js_var?>";
or
var strRooms = '<?=$js_var?>';
Use this in case of empty textbox
var strRooms ="<?php echo !empty($js_var) ? $js_var : 'Error message'; ?>";

Categories