Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6759535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:57:14+00:00 2026-05-26T13:57:14+00:00

I am making an ajax call in jquery $.get(validate_isbn.php, {isbn: obj[16]}, function(answer) { console.log(answer);

  • 0

I am making an ajax call in jquery

$.get("validate_isbn.php", {isbn: obj[16]},
                                        function(answer) 
                                        {                   
                                            console.log(answer);
                                            if (answer == "valid")
                                            {
                                                var checked1 = $(elements[index]).val();
                                                //$(elements[index]).val().append("<img src = 'pics/green_checkmark.png'>");    //doesn't work
                                                //elements.after("<img src = 'pics/green_checkmark.png'>");     //sets all the elements with this pic
                                                elements.eq(index).after("<img src='pics/green_checkmark.png' id='checkmark'>");
                                                var checked = $(elements[index]).val();
                                            }                                                                               
                                        });

which worked fine. I saw in the debugger that it was properly sending over the variable isbn with a isbn number from the obj array. My problem is on the php side. When I was testing, I simply had the code echo “valid” and everything worked out fine. But now when I put the real code in it stopped working:

<?php
//This algorithm is for ISBN 10
function is_isbn_10_valid($n){
$check = 0;
for ($i = 0; $i < 9; $i++) 
{
    $check += (10 - $i) * substr($n, $i, 1);    //starting at the leftmost digit, multiple each digit by a constant, starting at 10, add the total
}   
$t = substr($n, 9, 1); // tenth digit (aka checksum or check digit)
$check += ($t == 'x' || $t == 'X') ? 10 : $t;       //now add the tenth digit
return $check % 11 == 0;
}

//The algorithm for ISBN 13 validation is as follows:
//Multiply each digit of teh isbn, starting at the left, with 1,3,3... etc for the entire isbn (including the check digit becuase its 
//just going to be multiplied by 1 anyways.
//Add them all together, do mod 10 and voila!
function is_isbn_13_valid($n){
$check = 0;
for ($i = 0; $i < 13; $i+=2) //this does digits 1,3,5,7,9,10,11,13
{
    $check += substr($n, $i, 1);
}   
for ($i = 1; $i < 12; $i+=2) //this does digits 2,4,6,8,10,12
{
    $check += 3 * substr($n, $i, 1);
}   
return $check % 10 == 0;
}
$isbn = $_GET["isbn"];
if (strlen($isbn) = 10)
{
$result = is_isbn_10_valid($isbn);
}
else if (strlen($isbn) = 13) 
{
$result = is_isbn_13_valid($isbn);
}
else
{
$result false;
}
if ($result === true)
{echo "valid";}
else if ($result === false)
{echo "not valid";}
?>

(Note: I’m sure that I can be more efficient and just return the boolean, but I refrained from that at the moment since I wasn’t sure how the jquery .get would take it, as a boolean or text…)
Anyways, it doesn’t work. The error on the console.log gives me:

Fatal error: Can’t use function return value in write context in …pathname here…\validate_isbn.php on line 31

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T13:57:15+00:00Added an answer on May 26, 2026 at 1:57 pm

    On line 31, you have this:

    if ($strlen($isbn) = 10)
    

    Remove the $ on the strlen function, and change the = (assignment operator) to a == (equivalence operator). It should now look like this:

    if (strlen($isbn) == 10)
    

    You’ll need to do the same a few lines after that, too.

    Edit: One more thing. About five lines from the bottom, you’re missing an equal sign.

    $result false;
    

    Should be:

    $result = false;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a jquery ajax call to an mvc controller. I want to
I am using Rails and jQuery, making an ajax call initiated by clicking a
i am making ajax calls with jquery like this http://pastie.org/860837 and sometimes i get
I've rewritten my family web site using JavaScript (JQuery) making Ajax calls to PHP
I am making an AJAX calling using JQuery. I get back a JSON object
I am making an AJAX call (with jQuery) to retrieve a PartialView . Along
I'm making a ajax call using jQuery I'm making use of the following options
My encoding is set to ISO-8859-1. I'm making an AJAX call using jQuery.ajax to
I have a very strange problem. I'm making a pretty standard ajax-call with jQuery,
Quick background - I am making a jQuery ajax call to a service I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.